using System;
using System.Collections;
using System.Web.UI;
using System.Web.UI.WebControls;
using App_Code.Modules;
using Portal.Core.Helper;
using Portal.Data.Entity;

public partial class Modules_SimpleWebpart_List : SimpleWebpartModule
{
    private const int PageSize = 10;

    protected override void OnLoad(EventArgs e)
    {
        if (!IsPostBack)
        {
            int count = 0;
            IList list = SimpleWebpart.Paging(PageSize, GetCurrentPage(null), out count);

            Contents.DataSource = list;
            Contents.DataBind();

            AddPagingTool(new Control[] {phPagingBottom}, count, PageSize, null);
        }
    }

    protected void Contents_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        int id = Convert.ToInt32(e.CommandArgument);
        if (e.CommandName == "Delete")
        {
            (SimpleWebpart.FindByPrimaryKey(id)).Delete();
            Forward("delete");
        }
        else if (e.CommandName == "Edit")
        {
            ActionPage.newParams.Add("id", id);
            Forward("edit");
        }
    }
}